from pyecharts.charts import Bar
from pyecharts import options as opts
import pandas as  pd
import matplotlib.pyplot as plt
data_df = pd.read_csv('data_vastar.csv')
df = data_df.dropna()
df1 = df[['股票名称', '成交量']]
df2 = df1.iloc[:20]
print(df2['股票名称'].values)
print(df2['成交量'].values)
plt.figure(figsize=(10, 6))
 #https://cloud.tencent.com/developer/article/1441795
plt.tick_params(axis='x', labelsize=8)    # 设置x轴标签大小
plt.xticks(rotation=-15)
plt.rcParams['font.sans-serif'] = 'SimHei'
plt.bar(x=df2['股票名称'].values,height=df2['成交量'].values)
plt.title('成交量图表 - Volume chart')
plt.show()

c = (
    Bar()
        .add_xaxis(df2['股票名称'].values.tolist())
        .add_yaxis("股票成交量情况", df2['成交量'].values.tolist())
        .set_global_opts(
        title_opts=opts.TitleOpts(title="成交量图表 - Volume chart"),
        datazoom_opts=opts.DataZoomOpts(),
    )
    .render("data.html")
)

print('数据可视化结果完成,请在当前目录下查找打开 data.html 文件!')